package com.otdemo.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DBUtils {

    private String url = "jdbc:mysql://127.0.0.1:3306/dev?serverTimezone=GMT%2B8&characterEncoding=UTF-8";
//    private String url = "jdbc:mysql://gz-cynosdbmysql-grp-md3ujab7.sql.tencentcdb.com:29173/dev?serverTimezone=GMT%2B8&characterEncoding=UTF-8";
    private String username = "root";
//    private String password = "qnj183205.";  //数据库密码
    private String password = "123456";  //数据库密码

    public Connection getConnection() throws ClassNotFoundException, SQLException {
        //注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //获得连接
        Connection connection = DriverManager.getConnection(url, username, password);
        return connection;
    }

    public void closeConnection(Connection connection) throws SQLException {
        if (connection != null)
            connection.close();
    }

    public static void main(String[] args) throws Exception {
        DBUtils dbUtils = new DBUtils();
        dbUtils.getConnection();
    }
}
